package cn.platform.service.impl;

import cn.platform.entity.HarmonyChildMessage;
import cn.platform.entity.HarmonyTeacherClass;
import cn.platform.mapper.HarmonyTeacherMapper;
import cn.platform.response.AResponse;
import cn.platform.service.HarmonyTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.Year;
import java.util.List;

@Service
public class HarmonyTeacherServiceImpl implements HarmonyTeacherService {
    @Autowired
    private HarmonyTeacherMapper harmonyTeacherMapper;

    /**
     * 根据老师id查询老师信息
     *
     * @param id 老师id
     * @return AResponse res 老师的信息
     *
     * @author jyz
     */
    @Override
    public AResponse getRoleMessage(@PathVariable Integer id){
        AResponse res = new AResponse();
        res.setData(harmonyTeacherMapper.getRoleMessage(id));
        return res;
    }

    /**
     * 根据老师id查询所教班级
     *
     * @param id 老师id
     * @return AResponse res 老师的信息
     *
     * @author jyz
     */
    @Override
    public AResponse getTeacherClass(Integer id){
        AResponse res = new AResponse();
        // 通过年份相减计算年级
        List<HarmonyTeacherClass> classes = harmonyTeacherMapper.getTeacherClass(id);
        for (HarmonyTeacherClass clazz: classes){
            clazz.setGrade(String.valueOf(Year.now().getValue() - Integer.parseInt(clazz.getGrade()) + 1));
        }
        res.setData(classes);
        return res;
    }
}
